//
//  BookListColCell.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/13.
//

import UIKit

class BookListColCell: UICollectionViewCell {
    
    lazy var chaptersLabel: UILabel = {
        let label = UILabel()
        label.font = .wn_font(name: .bold, size: 16)
        label.textColor = .black
        return label
    }()

    lazy var arrowImage: UIImageView = {
        return UIImageView(image: UIImage(named: "setting_right_arrow"))
    }()
    
    lazy var statusLabel: UILabel = {
        let label = UILabel()
        label.textAlignment = .right
        label.font = .wn_font(name: .bold, size: 12)
        label.textColor = .init(named: "gray_999999")
        return label
    }()
    
    var model: BookDetailModel? {
        didSet {
            if let m = model {
                chaptersLabel.attributedText = "\(m.chapters) 章節".wn_numberChange(.black, .wn_font(name: .bold, size: 16))
                statusLabel.text = m.status == 1 ? "已完結" : "正在更新"
                isHidden = m.chapters == 0
            }
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(chaptersLabel)
        addSubview(arrowImage)
        addSubview(statusLabel)
        chaptersLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(12)
        }
        arrowImage.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.left.equalTo(chaptersLabel.snp.right).offset(2)
            make.width.height.equalTo(24)
        }
        statusLabel.snp.makeConstraints { (make) in
            make.centerY.equalToSuperview()
            make.right.equalTo(-12)
        }
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
